﻿using Rougamo.Context;
using Rougamo;

using System;

namespace 枸杞VBE插件
{
    internal class InfoAttribute : MoAttribute
    {
        public override AccessFlags Flags => AccessFlags.All;

        public override void OnEntry(MethodContext context) => Log.Info($"{context.Method.Name}开始运行");

        public override void OnException(MethodContext context) => Log.Error(context.Exception);

        public override void OnExit(MethodContext context) => Log.Info(context.Method.Name + "运行结束");

        public override void OnSuccess(MethodContext context) => Log.Info(context.Method.Name + "运行成功");
    }

    internal class DebugAttribute : MoAttribute
    {
#if DEBUG
        public override AccessFlags Flags => AccessFlags.All;

        public override void OnEntry(MethodContext context)
        {
            // 从context对象中能取到包括入参、类实例、方法描述等信息
            //Console.WriteLine(context.Method.Name + "方法执行前");

            if (context.Method.Name == "生成控件")
            {
                Log.Info($"{context.Method.Name}开始生成控件\t{context.Arguments[0]}\t{context.Arguments[1]}");
            }
            else
            {
                Log.Info($"{context.Method.Name}开始运行");
            }
        }

        public override void OnException(MethodContext context) => Log.Error(context.Exception);

        public override void OnExit(MethodContext context) => Log.Info(context.Method.Name + "运行结束");

        public override void OnSuccess(MethodContext context) => Log.Info(context.Method.Name + "运行成功");

#endif
    }
}